home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.net;
-
- import java.io.FilterOutputStream;
- import java.io.IOException;
- import java.io.OutputStream;
-
- class SocketWriter extends FilterOutputStream {
- byte[] _packetHeader = new byte[5];
-
- SocketWriter(OutputStream out) {
- super(out);
- this._packetHeader[0] = -69;
- }
-
- public synchronized void write(short ID, int b) throws IOException {
- byte[] i = new byte[1];
- i[0] = (byte)b;
- this.write(ID, i, 0, 1);
- }
-
- public synchronized void write(short ID, byte[] b) throws IOException {
- this.write(ID, b, 0, b.length);
- }
-
- public synchronized void write(short ID, byte[] b, int off, int len) throws IOException {
- int bufsize = len + 2;
- this._packetHeader[1] = (byte)(bufsize >> 8);
- this._packetHeader[2] = (byte)(bufsize & 255);
- this._packetHeader[3] = (byte)(ID >> 8);
- this._packetHeader[4] = (byte)(ID & 255);
- bufsize = len + 5;
- byte[] msgbufSend = new byte[bufsize];
- System.arraycopy(this._packetHeader, 0, msgbufSend, 0, 5);
- System.arraycopy(b, 0, msgbufSend, 5, len);
- super.out.write(msgbufSend, 0, bufsize);
- }
- }
-